<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@include file="/wx/page/session.jsp"%>
<c:set var="userId" value="${param.userId}" />
<c:set var="deptId" value="${param.deptId}" />
<c:set var="deptCode" value="${param.deptCode}" />
<c:set var="deptParentId" value="${param.deptParentId}" />
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <title>任务列表</title>
    <link rel="stylesheet" href="${ctx}/wx/css/default.css"/>
    <link rel="stylesheet" href="${ctx}/wx/css/mobiscroll.custom-2.5.0.min.css"/>
    <script type="text/javascript" src="${ctx}/wx/js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="${ctx}/wx/js/mobiscroll.custom-2.5.0.min.js"></script>
    <script type="text/javascript" src="${ctx}/wx/js/xtable.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/engine.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/util.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/interface/DeptService.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/interface/TaskService.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/interface/UserService.js"></script>
    <script type="text/javascript" src="${ctx}/wx/js/alert.js"></script>
</head>
<body>
    <p class="contact-submit">
        <input type="hidden" id="staffType" name="staffType" />
        <input type="button" value="添加任务" onclick="insertTask()">
    </p>
    <p class="contact-input">
        <select id="deptId" name="deptId" onchange="getTaskPage()">
        </select>
    </p>
    <p class="contact-input">
        <select id="taskType" name="taskTypa" onchange="getTaskPage()" style="width: 49%">
            <option value="">任务类型</option>
            <option value="1">煤贸</option>
            <option value="2">运输</option>
        </select>
        <select id="taskState" name="taskState" onchange="getTaskPage()" style="width: 50%">
            <option value="">任务状态</option>
            <option value="0">未完成</option>
            <option value="1">已完成</option>
        </select>
    </p>
    <p class="contact-input">
        <input type="tel" id="taskSenderUserMobile" name="taskSenderUserMobile" placeholder="货主电话" onchange="getTaskPage()" style="width: 48%">
        <input type="search" id="taskCreateTime" name="taskCreateTime" placeholder="创建日期" onchange="getTaskPage()" style="width: 50%">
    </p>
    <SCRIPT LANGUAGE="JavaScript" type="">
    var taskThead = new Array(
            new XThead("类型"),
            new XThead("货主"),
            new XThead("操作")
    );

    var taskXTable = new XTable("task", taskThead);

    taskXTable.XTbodyArray = function (model) {
        var staffType = dwr.util.getValue("staffType");
        var selfDeptState = "${deptId}" == model.deptId ? 1 : 0;
        var href1 = (model.taskType == 1 ? "煤贸" : model.taskType == 2 ? "运输" : "") + "<br>" + (model.taskState == 0 ? "未完成" : model.taskState == 1 ? "完成" : "") + "<br>" + (model.taskPublishState ? "已发布" : "未发布");
        var href2 = model.taskSenderUserName + "<br>" + model.taskSenderUserMobile + "<br>" + new Date(model.taskCreateTime).Format("MM/dd hh:mm");
        var href3 = "<a href='${ctx}/wx/page/bill_list.jsp?userId=${userId}&deptId=${deptId}&deptCode=${deptCode}&deptParentId=${deptParentId}&staffType=" + staffType + "&selfDeptState=" + selfDeptState + "&taskId=" + model.taskId + "&taskType=" + model.taskType + "&taskState=" + model.taskState + "&taskCostPrice=" + model.taskCostPrice + "'><input type='button' value='提&nbsp;&nbsp;货&nbsp;&nbsp;单'></a><br>";
        href3 += "<a href='${ctx}/wx/page/task_detail.jsp?userId=${userId}&deptId=${deptId}&deptCode=${deptCode}&deptParentId=${deptParentId}&taskId=" + model.taskId + "&staffType=" + staffType + "'><input type='button' value='任务详情'></a><br>";
        href3 += "<a href='${ctx}/wx/page/money_list.jsp?userId=${userId}&deptId=${deptId}&deptCode=${deptCode}&deptParentId=${deptParentId}&taskId=" + model.taskId + "&staffType=" + staffType + "'><input type='button' value='收支管理'></a>";
        var array = new Array(
                new XTbody("task", href1),
                new XTbody("task", href2),
                new XTbody("task", href3, null, null, null, "center")
        );

        return array;
    }
    taskXTable.getXList = function (page){
        var task = new Task();
        task.deptId = dwr.util.getValue("deptId");
        task.taskType = dwr.util.getValue("taskType");
        task.taskState = dwr.util.getValue("taskState");
        task.taskSenderUserMobile = dwr.util.getValue("taskSenderUserMobile");
        var taskCreateTime = dwr.util.getValue("taskCreateTime");
        if(taskCreateTime) {
            task.taskCreateTime = new Date(taskCreateTime);
        }
        task.pageIndex = page;
        task.pageSize = taskXTable.pageSize;
        TaskService.selectTaskList(task, function(list){taskXTable.addTable(list);});
    }
    function getTaskPage(){
        var task = new Task();
        task.deptId = dwr.util.getValue("deptId");
        task.taskType = dwr.util.getValue("taskType");
        task.taskState = dwr.util.getValue("taskState");
        task.taskSenderUserMobile = dwr.util.getValue("taskSenderUserMobile");
        var taskCreateTime = dwr.util.getValue("taskCreateTime");
        if(taskCreateTime) {
            task.taskCreateTime = new Date(taskCreateTime);
        }
        TaskService.selectTaskNum(task, function(num){taskXTable.setTotalPage(num);});
    }
    </SCRIPT>
</body>
</html>
<script type="text/javascript">
    $(function(){
        $("#taskCreateTime").mobiscroll().date();
        //初始化日期控件
        var opt = {
            preset: 'date', //日期，可选：date\datetime\time\tree_list\image_text\select
            theme: 'default', //皮肤样式，可选：default\android\android-ics light\android-ics\ios\jqm\sense-ui\wp light\wp
            display: 'modal', //显示方式 ，可选：modal\inline\bubble\top\bottom
            mode: 'scroller', //日期选择模式，可选：scroller\clickpick\mixed
            lang:'zh',
            dateFormat: 'yyyy/mm/dd', // 日期格式
            setText: '确定', //确认按钮名称
            cancelText: '取消',//取消按钮名籍我
            dateOrder: 'yyyymmdd', //面板中日期排列格式
            dayText: '日', monthText: '月', yearText: '年', //面板中年月日文字
            showNow: false,
            nowText: "今",
            startYear:2017, //开始年份
            endYear:2020 //结束年份
        };
        $("#taskCreateTime").mobiscroll(opt);
    });

    var dept = new Dept();
    dept.deptCode = "${deptCode}";
    DeptService.selectDeptList(dept, callbackSelectDeptList);

    function callbackSelectDeptList(list) {
        dwr.util.addOptions("deptId", list, "deptId", "deptName");
        var staff = new Staff();
        staff.userId = "${userId}";
        UserService.selectStaffList(staff, function (list) {
            staff = list[0];
            dwr.util.setValue("staffType", staff.staffType);
            getTaskPage();
        });
    }
    
    function insertTask() {
        var staffType = dwr.util.getValue("staffType");
        location = "${ctx}/wx/page/task_manage.jsp?userId=${userId}&deptId=${deptId}&deptCode=${deptCode}&deptParentId=${deptParentId}&staffType=" + staffType;
    }
</script>